package com.jiangruan.javaproject;

import com.alibaba.fastjson.JSONObject;
import com.jiangruan.javaproject.address.Address;
import com.jiangruan.javaproject.bean.HotVideo;
import com.jiangruan.javaproject.bean.HotVideoCommon;
import com.jiangruan.javaproject.bean.PRCCommon;
import com.jiangruan.javaproject.request.HttpUtils;
import com.jiangruan.javaproject.rpc.GetBestBlockHash;
import com.jiangruan.javaproject.service.HotVideoService;

import java.security.KeyPair;
import java.util.List;
import java.util.Scanner;

/**
 * @author zengguanlin
 * @email:zengguanlin@2977725281@qq.com
 * @desc:该类是Java项目的主函数的类，是程序的入口
 * @datatime:2021:12:19
 */
public class Main {
    public static void main(String []args){
        run();
    }
    public static void run(){
        System.out.println("比特币系统设计期末考察系统");
        System.out.println("本系统已实现以下功能：");
        System.out.println("1.热门视频抓取 2.和比特币客户端通信 3.比特币推导 0.退出");
        while (true){
            userMenu();
        }
    }
    public static void userMenu(){
        System.out.println("请输入要使用的功能序号：");
        System.out.println("1.热门视频抓取 2.和比特币客户端通信 3.比特币推导 0.退出");
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        switch (num){
            case 1://热门视频抓取
                HotVideoService hotVideo = new HotVideoService();
                List<HotVideo> videoList = hotVideo.getHotVideo();
                for (HotVideo video :videoList){
                    System.out.println(video.getShare_url());
                }
                break;
            case 2:
                PRCCommon bestBlockHash = GetBestBlockHash.getBestBlockHash();
                System.out.println("当前最高区块的hash值为:"+bestBlockHash.getResult());
                break;
            case 3:
                //生成
                Address address = new Address();
                KeyPair keyPair = address.generateKeys();
                String newAddress = address.newAddress(keyPair);
                System.out.println("比特币地址为:"+newAddress);

                //验证
                boolean isValid = address.validateAddr(newAddress);
                System.out.println("生成的比特币地址的真假性为:"+isValid);
                break;
            case 0:
                System.out.println("谢谢使用，下次再见");
                System.exit(0);
                break;
            default:
                System.out.println("输入有误，重新输入！");
                break;
        }
    }
}
